home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * MyHandlers.c
- *
- * Optional custom functions to handle special events. Includes:
- * document opening, startup and quitting
- *
- * Modify these functions if you need to add to the standard support
- * built into the framework.
- *
- * The function prototypes are contained in the relevent headers.
- * For example, AEHandlers.h contains the prototype for CustomOpenDocument
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1995,1996 by Grant Neufeld
- * grant@acm.com
- * http://arpp.carleton.ca/cgi/framework/
- *
- *****/
-
- #include "MyConfiguration.h"
-
- #if kCompileWithDragNDrop
- #include <Drag.h>
- #endif
-
- #include "AEHandlers.h"
- #include "CGI.h"
- #include "CustomHandlers.h"
- #include "DebugUtil.h"
- #include "EventUtil.h"
- #include "ListSTAR.h"
- #include "ProcessUtil.h"
- #include "Quit.h"
- #include "Startup.h"
- #include "WindowInt.h"
-
-
- /*** FUNCTIONS ***/
-
- /* The application is expected to open the given document, if possible */
- OSErr
- CustomOpenDocument ( FSSpec *theFile )
- {
- OSErr theErr;
-
- my_assert ( theFile != NULL, "\pCustomOpenDocument: theFile ptr is NULL" );
-
- theErr = noErr;
-
- return theErr;
- } /* CustomOpenDocument */
-
-
- /** WINDOWS **/
- #pragma mark -
-
- #pragma segment Utilities
- /* Close any custom application windows */
- #if kCompileWithApplicationWindows
- OSErr
- CustomCloseWindow ( WindowPtr theWindow )
- {
- OSErr theErr;
-
- theErr = noErr;
-
- return theErr;
- } /* CustomCloseWindow */
- #endif
-
-
- /* If activate is true, restore theWindow's selections.
- If activate is false, hide, or reduce to outline, theWindow's selections.
- If theWindow has a grow box in the bottom right corner,
- you should invalidate the growrect */
- #if kCompileWithApplicationWindows
- void
- CustomActivateWindow ( WindowPtr theWindow, Boolean activate )
- {
-
- } /* CustomActivateWindow */
- #endif
-
-
- /* Draw contents of window on an update event */
- #if kCompileWithApplicationWindows
- void
- CustomUpdateWindow ( WindowPtr theWindow )
- {
-
- } /* CustomUpdateWindow */
- #endif
-
-
- /* Support a click in a window.
- If the click is on a dragable item, set onDragItem to true. */
- #if kCompileWithApplicationWindows
- void
- CustomClickInWindow ( WindowPtr theWindow, Point thePoint, Boolean *onDragItem )
- {
-
- } /* CustomClickInWindow */
- #endif
-
-
- /* Grow the window */
- #if kCompileWithApplicationWindows
- void
- CustomGrowWindow ( WindowPtr theWindow, Point thePoint )
- {
- /* this call is in here by default. You can replace it with your own custom
- handler if you want */
- WindowGrowHandler ( theWindow, thePoint );
- } /* CustomGrowWindow */
- #endif
-
-
- /* Handle Idle time tasks for a window. */
- #if kCompileWithApplicationWindows
- void
- CustomWindowIdle ( WindowPtr theWindow )
- {
-
- } /* CustomWindowIdle */
- #endif
-
-
- /* If you add windows that allow for text entry or you accept non-command-key
- keyboard input, you need to support this function. */
- #if kCompileWithKeyboardEvents
- void
- CustomKeyPress ( EventRecord *theEvent )
- {
-
- } /* CustomKeyPress */
- #endif
-
-
- /* */
- #if kCompileWithDragNDrop
- OSErr
- CustomDoStartDrag ( EventRecord *theEvent, WindowPtr theWindow )
- {
- OSErr theErr;
- GrafPtr savePort;
- DragReference theDrag;
- RgnHandle dragRegion;
-
- GetPort ( &savePort );
- SetPort ( (GrafPtr)theWindow );
-
- theErr = NewDrag ( &theDrag );
-
- if ( theErr == noErr )
- {
- dragRegion = NewRgn ();
-
- /* ••• You need to call a function that sets up the drag values such as:
- theErr = customSetupDrag ( theWindow, theDrag, dragRegion, theEvent->where ); */
- }
- else
- {
- theDrag = nil;
- }
-
- SetPort ( savePort );
-
- theErr = TrackDrag ( theDrag, theEvent, dragRegion );
-
- if ( dragRegion != CustomOpenDocument )
- {
- DisposeRgn ( dragRegion );
- }
-
- if ( theDrag != nil )
- {
- DisposeDrag ( theDrag );
- }
-
- return theErr;
- } /* CustomDoStartDrag */
- #endif
-
-
- /* This will be called if you have a dialog window (that is either modeless or
- moveable-modal) that receives a mouseDown */
- #if kCompileWithApplicationWindows
- void
- CustomDialogMouseDown ( EventRecord *theEvent, DialogPtr theDialog, short itemHit )
- {
-
- } /* CustomDialogMouseDown */
- #endif
-
-
- /** OTHER TASKS **/
- #pragma mark -
-
- /* The prototype for this function is in "ProcessUtil.h" */
- #if kCompileWithPeriodicTask
- void
- CustomPeriodicTask ( void )
- {
- //•••WARNING: THIS DOESN'T EXECUTE EXCEPT WHEN COMPILING AS WEBSTAR PLUG-IN.
- // THIS WILL BE FIXED IN A FUTURE VERSION
-
- } /* CustomPeriodicTask */
- #endif
-
-
-
- /* The prototype for this function is in "ProcessUtil.h" */
- #if kCompileWithDeferredTask
- void
- CustomDeferredTask ( void )
- {
- //•••WARNING: THIS DOESN'T EXECUTE IF COMPILING AS WEBSTAR PLUG-IN.
- // THIS WILL BE FIXED IN A FUTURE VERSION
-
- } /* CustomDeferredTask */
- #endif
-
-
- /** STARTUP / SHUTDOWN **/
- #pragma mark -
-
- #pragma segment Startup
- /* Put any of the initialization you need done, here.
- This function will be called once:
- for CGIs: in-between the startup sequence and the main event loop
- for plug-ins: as part of the WSAPI_Init event
- Return noErr / WSAPI_I_NoErr if the initialization was successful,
- otherwise return an error value.
-
- If compiling as a normal CGI:
- Add things like installing additional AppleEvent handlers in this function.
- commandPtr is not available (WSAPI only).
- An error result will cause the application to quit.
-
- If compiling as a WSAPI plug-in:
- Do not make any interface calls or other calls that cannot be handled by
- the WSAPI unless you wrap those calls in
- #if !(kCompilingForWSAPI)
- ...
- #endif
- Do not call ProcessGiveTime unless you want to modify the function
- 'WSAPI_Dispatch' in "CGI.c" to not change the resource file reference,
- in which case you will be responsible for setting the resource ref
- if you need to access resources in your own (and not the server's)
- resource fork.
- commandPtr is available. See WSAPI documentation for details.
- An error result will cause the plug-in to not be loaded by the server.
- Any memory allocation or deallocation must be done using direct WSAPI
- calls */
- SInt32
- CustomStartup (
- #if kCompilingForWSAPI
- WSAPI_CommandPBPtr commandPtr
- #else
- void
- #endif
- )
- {
- #if kCompilingForWSAPI
- /* remove or comment-out this line if you use commandPtr */
- #pragma unused(commandPtr)
- #endif
-
- SInt32 theErr;
-
- /* these really have not difference - since both constants equal zero */
- #if kCompilingForWSAPI
- theErr = WSAPI_I_NoErr;
- #else
- theErr = noErr;
- #endif
-
- return theErr;
- } /* CustomStartup */
-
-
- #pragma segment Main
- /* This function is called at quitting time. Put any cleanup you need to do in it.
- Return true if you are successful.
- Return false if you are unable to quit for some reason (this generally only
- applies when the user cancels).
- allowUserInteract specifies whether you can make user interface calls.
- However, CGIs generally should not rely on any user interface calls, so don't
- depend on them. */
- Boolean
- CustomQuit ( Boolean allowUserInteract )
- {
- /* remove or comment-out the following line if you use the allowUserInteract param */
- #pragma unused(allowUserInteract)
-
- return true;
- } /* CustomQuit */
-
-
- #pragma segment Main
- /* this function is called if some sort of emergency has arisen.
- What you're basically being asked to do is release any memory,
- resources, files, etc. that you can. */
- void
- CustomEmergencyHandler ( void )
- {
-
- } /* CustomEmergencyHandler */
-
-
- /***** EOF *****/
-